package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

public class UpdateTelephoneOrders {
	
	private String value;
	private String orderId;
	private Vector<String> order;
	private int status=0;
	
	

	public UpdateTelephoneOrders (String v, String id)
	{
		this.value=v;
		this.orderId=id;
	}
	
	public UpdateTelephoneOrders (Vector<String> o)
	{
		this.order=o;
	}
	
	
	
	
	public void updateStatus()
	{
       SQLConnection sc=new SQLConnection();
		try {
			
			PreparedStatement ps1 = sc.getConnection().prepareStatement("UPDATE telephoneorder SET status=? WHERE telOrderId=? ;");				
			sc.getConnection().setAutoCommit(false);
			ps1.setString(1,value);
			ps1.setString(2,orderId);
			ps1.executeUpdate();
			sc.getConnection().commit();
			ps1.close();
			sc.getConnection().close();
			
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
	}
	
	
	
	public void updateTable()
	{
       SQLConnection sc=new SQLConnection();
		try {
			
			PreparedStatement ps1 = sc.getConnection().prepareStatement("UPDATE telephoneorder SET restTable=? WHERE telOrderId=? ;");				
			sc.getConnection().setAutoCommit(false);
			ps1.setString(1,value);
			ps1.setString(2,orderId);
			ps1.executeUpdate();
			sc.getConnection().commit();
			ps1.close();
			sc.getConnection().close();
			
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
	}
	
	
	
	
	public void updateOrder()
	{
       SQLConnection sc=new SQLConnection();
		try {
			
			PreparedStatement ps1 = sc.getConnection().prepareStatement("UPDATE telephoneorder SET date=?,time=?,name=?,numOfPersons=?,phoneNo=?,comments=? WHERE telOrderId=? ;");				
			sc.getConnection().setAutoCommit(false);
			ps1.setString(1,order.get(1));
			ps1.setString(2,order.get(2));
			ps1.setString(3,order.get(3));
			ps1.setString(4,order.get(4));
			ps1.setString(5,order.get(5));
			ps1.setString(6,order.get(6));
			ps1.setString(7,order.get(0));
			ps1.executeUpdate();
			sc.getConnection().commit();
			status=1;
			ps1.close();
			sc.getConnection().close();
			
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			status=0;
			e.printStackTrace();
			
		}
	}
	
	
	
	
	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
}
